﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using Framework.Data;

namespace Framework.Core
{
    internal class RoleInfoDataAccess : BaseDataAccess
    {
        /// <summary>
        /// 加载角色信息
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        internal RoleInfo GetRole(string roleID)
        {
            using (var context = DataHelper.GetBaseDbContext())
            {
                var sql = "SELECT [Role_Info].[sRoleID],[Role_Info].[sRoleName] FROM [Role_Info] WHERE [Role_Info].[sRoleID]=@RoleID";
                var role =
                    context.Sql(sql).Parameter("RoleID", roleID).QuerySingle<RoleInfo>(delegate(RoleInfo roleMap, IDataReader roleReader)
                    {
                        roleMap.RoleID = roleReader.GetString("sRoleID");
                        roleMap.RoleName = roleReader.GetString("sRoleName");
                        roleMap.RuleInfos = new List<RuleInfo>();
                    });

                return role;
            }
        }
    }
}
